package one_to_one;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.Socket;


/**
 * @author Xu,
 * @data 2021/1/3，
 * @time 17:25
 */
public class Consumer {
    public static int times = 1000;

    public Consumer() {

    }

    public static void IsPrimaryNumber(long number) {
        BigInteger bigInteger = BigInteger.valueOf(number);
        bigInteger.isProbablePrime(50);
    }

    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        Socket socket = null;
        for(int i = 0 ; i < times ; i++) {
            String host = "localhost";
            int port = 10303;
            socket = new Socket(host, port);
            String msg = "c" + " ";
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write(msg.getBytes("UTF-8"));
            InputStream inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024*60];
            int len;
            StringBuilder stringBuilder = new StringBuilder();
            while((len = inputStream.read(bytes)) != -1) {
                stringBuilder.append(new String(bytes,0,len,"UTF-8"));
                String string = stringBuilder.toString();
                String[] strings = string.split(" ");
                for(int j=0;j<strings.length;j++) {
                    long number = Long.parseLong(strings[j]);
                    IsPrimaryNumber(number);
                }
            }
            socket.shutdownInput();
            socket.shutdownOutput();
        }
        long end = System.currentTimeMillis();
        System.out.println("runtime: " + (end - start)/1000.0 + "s");

}
}


